package com.ljl.ssm.controller;


import com.ljl.ssm.entity.User;
import com.ljl.ssm.service.IRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller

public class RegistController {
    @Autowired
    IRegisterService registerService;
    @RequestMapping(value = "/userInfo",method = RequestMethod.POST)
    public String register(User user, Model model){
        System.out.println(user.toString());
        if(user.getName().isEmpty()||user.getPassword().isEmpty()){
            model.addAttribute("msg2","用户名及密码均不能为空，请修改");
            return "register";
        }
        else {
            int result=registerService.select(user);
            if(result==0) {
                model.addAttribute("msg2", "该用户名已被注册");
                return "register";
            }
            else {
             //   model.addAttribute("msg2", "注册成功");
                return "login";
            }
        }
    }
}
